package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowStoreRegionPrice;
import cn.stylefeng.guns.modular.manager.mapper.FlowStoreRegionMapper;
import cn.stylefeng.guns.modular.manager.mapper.FlowStoreRegionPriceMapper;
import cn.stylefeng.guns.modular.manager.model.params.FlowStoreRegionParam;
import cn.stylefeng.guns.modular.manager.model.params.FlowStoreRegionPriceParam;
import cn.stylefeng.guns.modular.manager.model.result.FlowStoreRegionPriceResult;
import cn.stylefeng.guns.modular.manager.service.FlowStoreRegionPriceService;
import cn.stylefeng.guns.modular.manager.service.FlowStoreRegionService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

@Service
public class FlowStoreRegionPriceServiceImpl extends ServiceImpl<FlowStoreRegionPriceMapper, FlowStoreRegionPrice> implements FlowStoreRegionPriceService {
    @Override
    public void add(FlowStoreRegionPriceParam param) {
        FlowStoreRegionPrice entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FlowStoreRegionPriceParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(FlowStoreRegionPriceParam param) {
        FlowStoreRegionPrice oldEntity = getOldEntity(param);
        FlowStoreRegionPrice newEntity = getEntity(param);


        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FlowStoreRegionPriceResult findBySpec(FlowStoreRegionPriceParam param) {
        return null;
    }

    @Override
    public List<FlowStoreRegionPriceResult> findListBySpec(FlowStoreRegionPriceParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FlowStoreRegionPriceParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private FlowStoreRegionPrice getEntity(FlowStoreRegionPriceParam param) {
        FlowStoreRegionPrice entity = new FlowStoreRegionPrice();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    private Serializable getKey(FlowStoreRegionPriceParam param){
        return param.getRegionId();
    }

    private FlowStoreRegionPrice getOldEntity(FlowStoreRegionPriceParam param) {
        return this.getById(getKey(param));
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }
}
